#include <graphics.h>
#include <conio.h>
#include <time.h>
#include <stdio.h>
#pragma comment(lib,"Winmm.lib")
void topic();				

int main()
{
	initgraph(480, 320);
	topic();				
	initgraph(800, 700);
	while (1)
	{
		
	}
	_getch();
	closegraph();
	return 0;

}

void topic()
{
	IMAGE back;
	mciSendString("open D:\\background.mp3 alias bkmusic", NULL, 0, NULL);
	mciSendString("play bkmusic repeat", NULL, 0, NULL);
	loadimage(&back, "D:\\background.jpg");
	putimage(0, 0, &back);

	settextcolor(COLORREF RGB(255, 255, 255));
	outtextxy(200, 200, "按任意键开始游戏");
	_getch();
}	

void SnakeMove()
{
	int i, j;
	for (i = snake.lenth - 1; i > 0; i--)
	{
		snake.xy[i].x = snake.xy[i - 1].x;
		snake.xy[i].y = snake.xy[i - 1].y;
	}
	switch (snake.position)
	{
	case sup:
		snake.xy[0].y -= 10;
		break;
	case sdown:
		snake.xy[0].y += 10;
		break;
	case sright:
		snake.xy[0].x += 10;
		break;
	case sleft:
		snake.xy[0].x -= 10;
		break;
	case paus:
		_getch();
		break;
	}
	while (_kbhit())
	{
		char key = _getch();

		switch (key)
		{
		case up:
			if (snake.position != sdown)
				snake.position = sup;
			break;
		case down:
			if (snake.position != sup)
				snake.position = sdown;
			break;
		case left:
			if (snake.position != sright)
				snake.position = sleft;
			break;
		case right:
			if (snake.position != sleft)
				snake.position = sright;
			break;
		case 'p':
			system("pause");
			break;
		}
	}
	Sleep(150);

	for (j = 2; j < snake.lenth; j++)
	{
		if (snake.xy[0].x == snake.xy[j].x && snake.xy[0].y == snake.xy[j].y)
			gameover();
	}
}

void speedup()
{
	switch (Food.grade)
	{
		case 0: snake.speed = 120; break;
		case 10: snake.speed = 120; break;
		case 20: snake.speed = 120; break;
		case 30: snake.speed = 100; break;
		case 40: snake.speed = 100; break;
		case 50: snake.speed = 100; break;
		case 60: snake.speed = 85; break;
		case 70: snake.speed = 85; break;
		case 80: snake.speed = 70; break;
		case 90: snake.speed = 70; break;
		case 100:snake.speed = 60; break;
		case 110:snake.speed = 60; break;
		case 120:snake.speed = 55; break;
		case 130:snake.speed = 55; break;
		case 140:snake.speed = 50; break;
		case 150:snake.speed = 50; break;
		case 160:snake.speed = 50; break;
		default:snake.speed = 40; break;
	}
}